
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="icon" href="../../favicon.ico">

    <title>班级留言板</title>

    <!-- Bootstrap core CSS -->
    <link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">

    <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
    <link href="../../assets/css/ie10-viewport-bug-workaround.css" rel="stylesheet">

    <!-- Custom styles for this template -->
    <link href="jumbotron.css" rel="stylesheet">

    <!-- Just for debugging purposes. Don't actually copy these 2 lines! -->
    <!--[if lt IE 9]><script src="../../assets/js/ie8-responsive-file-warning.js"></script><![endif]-->
    <script src="../../assets/js/ie-emulation-modes-warning.js"></script>

    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
    <script src="https://cdn.bootcss.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    <style>
        .img{
            width: 80px;
            height: 80px;
        }
        .container{
            margin: 0 auto;
        }
        font,a,h1{
            font-family: "微软雅黑";
        }
        .message{
            margin-top: 100px;
        }
        .name{
            margin-left: 20px;
        }
    </style>
</head>

<body>
<% include header.ejs%>
<!-- Main jumbotron for a primary marketing message or call to action -->
<% if(!login){%>
<div class="container jumbotron row">
    <div class="container col-sm-6">
        <h1>
            <a href="/setAvatar">
                <img class="img" <%if(avatar){%>src="/avatar/<%=avatar%>" <%}else{%>src="/avatar/default.jpg"<%}%>alt="">
            </a>
            欢迎!
        </h1>
        <p>班级留言是我们交流的平台，欢迎注册登录，请大家畅所欲言~~</p>
        <p><a class="btn btn-primary btn-lg" href="/regist" role="button">注册 &raquo;</a></p>
    </div>
    <div class="col-sm-6">
        <div class="container">
            <p>已有账号登录</p>
            <form class="form-signin">
                <p>用户名</p>
                <label for="inputEmail" class="sr-only"></label>
                <input type="text" id="name" name="name" class="form-control" placeholder="请输入您的用户名" required autofocus>
                <p>密码</p>
                <label for="inputPassword" class="sr-only"></label>
                <input type="password" id="pwd" name="pwd" class="form-control" placeholder="请输入您的密码" required><br>
                <button class="btn btn-lg btn-primary btn-block" type="button" id="btn">登录</button>
            </form>
        </div>
    </div>
</div>
<%}else{%>
<div class="row container message">
    <div class="col-sm-2">
        <a href="/setAvatar">
            <img class="img" <%if(avatar){%>src="/avatar/<%=avatar%>" <%}else{%>src="/avatar/default.jpg"<%}%>alt="">
        </a>
        <p class="name"><%=username%></p>
    </div>
    <div class="col-sm-10">
        <form class="form-horizontal" action="message">
            <div class="form-group">
                <textarea class="form-control liuyan" rows="3" name="message"></textarea>
            </div>
            <div class="form-group">
                <div>
                    <button type="submit" class="btn btn-success">发表留言</button>
                </div>
            </div>
        </form>
    </div>
</div>
<%}%>
<div class="container">
    <nav aria-label="pagination ">
        <ul class="pagination">
            <%for(var i=1;i<=page;i++){%>
            <li data-page="<%=i%>"><a href="/page?page=<%=i%>"><%=i%></a></li>
            <%}%>
        </ul>
        <hr>
    </nav>
</div>

<div class="container">
    <hr>
    <footer>
        <p>&copy; 2016 Company, Inc.</p>
    </footer>
</div> <!-- /container -->
<div class="message" id="allMessage"></div>
<script type="text/template" id="muban">
    <ul>
        <li>【姓名】{{=name}}</li>
        <li>【留言】{{=message}}</li>
        <li>【时间】{{=time}}</li>
        <li><a href="/del?_id={{=_id}}">删除</a></li>
    </ul>
</script>
<script src="js/jquery.min.js"></script>
<script src="js/underscore-no-min.js"></script>
<script src="./fenye.js"></script>

<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="../../assets/js/vendor/jquery.min.js"><\/script>')</script>
<script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<script src="../../assets/js/ie10-viewport-bug-workaround.js"></script>
</body>
<script>
    $("#btn").on("click", function (e) {
        $.ajax({
            url:"/doLogin",
            type:"post",
            data:{
                "username":$("#name").val(),
                "pwd":$("#pwd").val()
            },
            success:function(result){
                console.log(result);
                if(result=="1"){
                    alert("登录成功 点击确定跳转");
                    window.location.href="/";
                }else if(result=="-2"){
                    alert("密码错误");
                }
            }
        })
    });
</script>
</html>